#!/usr/bin/envpython
# -*-coding:UTF-8-*-
'''
@File    :   v2.py
@Contact :   308711822@qq.com
@License :   (C) Copyright 2021-2225, Personal exclusive right.

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2023/2/4 23:38   小钟同学      1.0         None
'''
import dataclasses
import inspect
from enum import Enum
from functools import partial
from typing import Any, Callable, Dict, List, Tuple, Type, TypeVar, cast, get_type_hints, Union, Optional

from fastapi import APIRouter
from pydantic.typing import AnyCallable


def RestInjectAPIRouter(prefix,tags,*args, **kwargs):
    def back(cls):
        if not hasattr(cls,'router'):
            cls.router = APIRouter(*args, **kwargs)
        else:
            pass
            print("已经初始化过了！！！")
        return cls

    return back




# class RoutableV2:
#     """Base class for all classes the want class-based routing.
#
#     This Uses RoutableMeta as a metaclass and various decorators like @get or @post from the decorators module. The
#     decorators just mark a method as an endpoint. The RoutableMeta then converts those to a list of desired endpoints in
#     the _endpoints class method during class creation. The constructor constructs an APIRouter and adds all the routes
#     in the _endpoints to it so they can be added to an core_app via FastAPI.include_router or similar.
#     """
#     #  Optional[Sequence[Callable[[], Any]]] = None
#     _endpoints: List[Callable] = []
#     prefix: str = ""
#     tags: Optional[List[Union[str, Enum]]] = None
#
#     def __init__(self, *args, **kwargs) -> None:
#         self.router = APIRouter(*args, **kwargs)
#         self.router.prefix = self.prefix
#         self.router.tags = self.tags
#
#
#         print("路由所属组当前所有的函数列表信息", self._endpoints)
#         for endpoint in self._endpoints:
#
#             # 给当前的函数注入本身的对象self
#             self.router.add_api_route(endpoint=partial(endpoint.endpoint, self),
#                                       **dataclasses.asdict(endpoint.args))